import printJS from 'print-js'

/**
 * 打印HTML元素
 */
export function printElement(elementId: string) {
  printJS({
    printable: elementId,
    type: 'html',
    targetStyles: ['*'],
    style: `
      @media print {
        body { margin: 0; padding: 20px; }
        .no-print { display: none; }
      }
    `
  })
}

/**
 * 打印表格数据
 */
export function printTable(data: any[], columns: { key: string; label: string }[], title?: string) {
  const header = columns.map(col => col.label)
  const properties = columns.map(col => col.key)
  
  printJS({
    printable: data,
    properties,
    type: 'json',
    header: title,
    gridHeaderStyle: 'color: #000; border: 1px solid #ccc; font-weight: bold;',
    gridStyle: 'border: 1px solid #ccc;'
  })
}

